#pragma once

#include <memory>
#include <functional>
#include <any>
#include <map>

typedef int int32;
typedef unsigned int uint32;

class CParamSet;
typedef std::shared_ptr<CParamSet>	ParamSetRef;
typedef std::weak_ptr<CParamSet>	ParamSetWeakRef;

class CParamSet
{
public:
	template<int32 KEY, typename T>
	bool Has()
	{
		return m_mapAny.find(KEY) != m_mapAny.end();
	}

	template<int32 KEY, typename T>
	T Get()
	{
		MAP_ANY::iterator it = m_mapAny.find(KEY);
		if (it != m_mapAny.end())
		{
			try
			{
				printf("any cast. \n");
				return std::any_cast<T>(it->second);
			}
			catch (std::bad_any_cast& e)
			{
				//Error log

				printf("CParamSet get catch: %s.\n", e.what());
				return T();
			}
		}
		return T();
	}

	template<int32 KEY, typename T>
	void Set(const T& value)
	{
		m_mapAny[KEY] = value;
	}

	void Clear() { m_mapAny.clear(); }

	static ParamSetRef CreateNew()
	{
		ParamSetRef r(new CParamSet());
		return r;
	}
private:
	typedef std::map<uint32, std::any> MAP_ANY;
	MAP_ANY m_mapAny;
};